<template>
  <div>
    <el-row class="tac">
      <el-col :span="24">
        <h5>
          <router-link to="/"> 小U商城后台 </router-link>
        </h5>
        <!-- default-active默认激活的菜单对应的index -->
        <!-- router：是否开启路由模式，开启后会以index作为路径跳转 -->
        <el-menu
          router
          :default-active="$route.path"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item index="/">
            <i class="el-icon-setting"></i>
            <span slot="title">首页</span>
          </el-menu-item>
          <!-- icon组件，class不同图标也不同 -->
          <!-- <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-setting"></i>
              <span>系统设置</span>
            </template>
            <el-menu-item index="/menu">菜单管理</el-menu-item>
            <el-menu-item index="/role">角色管理</el-menu-item>
            <el-menu-item index="/user">管理员管理</el-menu-item>
          </el-submenu>
          <el-submenu index="1">
            <template slot="title">
              <i class="el-icon-goods"></i>
              <span>商城管理</span>
            </template>
            <el-menu-item index="/category">商品分类</el-menu-item>
            <el-menu-item index="/specs">商品规格</el-menu-item>
            <el-menu-item index="/goods">商品管理</el-menu-item>
          </el-submenu> -->
          <el-submenu v-for="(item, index) in myMenus" :key="index" :index="index+''">
            <template slot="title">
              <i :class="item.icon"></i>
              <span>{{item.title}}</span>
            </template>
            <el-menu-item v-for="(subItem, subIndex) in item.children" :key="'sub'+subIndex" :index="subItem.url">{{subItem.title}}</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-col>
    </el-row>
    <!-- <el-button @click="clearUserInfo">退出登录</el-button> -->
  </div>
</template>

<script>
import {mapGetters, mapMutations} from 'vuex'
export default {
  computed: {
    // 辅助函数的作用：将store中的state、getters、mutations、actions映射到组件中，方便使用
    // mapGetters和mapState将数据映射到组件,当作自己数据来用
    // mapMutation和mapActions将函数映射到组件，当作自己的函数来用
    ...mapGetters([
      'myMenus'
    ])
  },
  methods: {
    ...mapMutations([
      'clearUserInfo'
    ]),
    logout() {
      this.$store.commit('clearUserInfo')
    }
  }
};
</script>

<style>
</style>